home *** CD-ROM | disk | FTP | other *** search
- /*______________________________________________________*/
- /* Palette Demo */
- /* by */
- /* RICHARD P. COLLYER */
- /* Developer Technical Support */
- /* Apple Computer, Inc. */
- /* 08/15/90 */
- /*______________________________________________________*/
-
- #include <CType.h>
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <desk.h>
- #include <dialogs.h>
- #include <Events.h>
- #include <GestaltEqu.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <OSEvents.h>
- #include <Palette.h>
- #include <SegLoad.h>
- #include <Resources.h>
- #include <ToolUtils.h>
- #include <StdIO.h>
- #include <QDOffscreen.h>
-
- extern _DataInit();
-
- #define pmInhibitG2 0x0100
- #define pmInhibitC2 0x0200
- #define pmInhibitG4 0x0400
- #define pmInhibitC4 0x0800
- #define pmInhibitG8 0x1000
- #define pmInhibitC8 0x2000
-
- #define TRUE 0xFF
- #define FALSE 0
- #define Gestalttest 0xA1AD
- #define NoTrap 0xA89F
-
- #define appleID 128
- #define appleMenu 0
- #define aboutMeCommand 1
-
- #define fileID 129
- #define quitCommand 1
-
- #define PaletteID 130
- #define CourCommand 1
- #define TolCommand 2
- #define ExpCommand 3
- #define AniCommand 4
- #define TolExpCommand 6
- #define TolAniCommand 7
- #define ExpAniCommand 8
- #define TEACommand 10
-
- #define PictID 128
- #define clutID 150 // If you would like gray scale then change 150 to 36
-
- #define aboutMeDLOG 128
- #define okButton 1
- #define authorItem 2
- #define languageItem 3
- #define numcolor 256
-
- Rect TotalRect, minRect, WinMinusScroll, InitWindowSize;
- WindowPtr myWindow;
- CTabHandle mycolors;
- PaletteHandle srcPalette;
- Boolean DoneFlag;
- MenuHandle mymenu1, mymenu2, mymenu0;
- PicHandle ThePict;
- GWorldPtr offscreenGWorld;
-
- /*______________________________________________________*/
- /* Check Correct Menu */
- /*______________________________________________________*/
- void CheckMenu(int whichMenu)
- /* This procedure checks and unchecks the appropriate menus */
- {
- CheckItem(mymenu2,CourCommand,FALSE);
- CheckItem(mymenu2,TolCommand,FALSE);
- CheckItem(mymenu2,ExpCommand,FALSE);
- CheckItem(mymenu2,AniCommand,FALSE);
- CheckItem(mymenu2,TolExpCommand,FALSE);
- CheckItem(mymenu2,TolAniCommand,FALSE);
- CheckItem(mymenu2,ExpAniCommand,FALSE);
- CheckItem(mymenu2,TEACommand,FALSE);
- switch (whichMenu) {
- case CourCommand:
- CheckItem(mymenu2,CourCommand,TRUE);
- break;
- case TolCommand:
- CheckItem(mymenu2,TolCommand,TRUE);
- break;
- case ExpCommand:
- CheckItem(mymenu2,ExpCommand,TRUE);
- break;
- case AniCommand:
- CheckItem(mymenu2,AniCommand,TRUE);
- break;
- case TolExpCommand:
- CheckItem(mymenu2,TolExpCommand,TRUE);
- break;
- case TolAniCommand:
- CheckItem(mymenu2,TolAniCommand,TRUE);
- break;
- case ExpAniCommand:
- CheckItem(mymenu2,ExpAniCommand,TRUE);
- break;
- case TEACommand:
- CheckItem(mymenu2,TEACommand,TRUE);
- break;
- defalut:
- break;
- }
- }
-
- /*______________________________________________________*/
- /* Set Up Usage of Palette */
- /*______________________________________________________*/
- void Draw()
- {
- RGBColor black = {0,0,0}, White = {65535,65535,65535};
-
- RGBForeColor (&black);
- RGBBackColor (&White);
- CopyBits ((BitMap *) *offscreenGWorld->portPixMap, &myWindow->portBits,
- &InitWindowSize, &WinMinusScroll, srcCopy, nil);
- }
-
- /*______________________________________________________*/
- /* Set Up Usage of Palette */
- /*______________________________________________________*/
- void SetInhibited(int Usage)
- /* When the usage of the palette changes I need to rebuild the palette,
- so I call this routine. I need to call SetEntryUsage on all of the entries
- of the palette, but I want to make sure that if the monitor is set to a bit depth
- low than 8 bits that the palette is limited in its colors. So the first two colors
- (not including white) are set to work at all depths except 1 bit mode. The next
- 12 entries are set to work on all depths except 1 & 2 bit modes. The rest of
- the colors are set to only work in 8 bit mode. I have also set the tolerance to
- hex 1500. With this tolerance I will be able to get most of the colors I need
- and those that I don't get exact will be very close. */
- {
- int i;
-
- CTab2Palette (mycolors, srcPalette, Usage, 0x1500);
- for (i = 1; i <= 2; ++i) {
- SetEntryUsage (srcPalette, i, Usage, 0x1500);
- }
- for (i = 3; i <= 14; ++i) {
- SetEntryUsage (srcPalette, i, Usage+pmInhibitG2+pmInhibitC2, 0x1500);
- }
- for (i = 15; i < numcolor; ++i) {
- SetEntryUsage (srcPalette, i, Usage+pmInhibitG2+pmInhibitC2+
- pmInhibitG4+pmInhibitC4, 0x1500);
- }
- }
-
- /*______________________________________________________*/
- /* About Prog Dialog